package com.xiguthings.xiniu.iot.postproducer.worker.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.xiguthings.xiniu.iot.common.PostData;
import com.xiguthings.xiniu.iot.postproducer.worker.kafka.KafkaClient;
import com.xiguthings.xiniu.iot.postproducer.worker.producer.ProcduceMessageCenter;

@Component
public class PostProducerContrller {

    private final Logger LOGGER = LoggerFactory.getLogger(PostProducerContrller.class);
    @Autowired
    private ProcduceMessageCenter procduceMessageCenter;

    @Autowired
    private KafkaClient kafkaClient;

    /**
     * 接收从kafka过来的消息
     *
     * @param data
     */
    public void receiveData(String data) {
        if (data == null) {
            return;
        }
        procduceMessageCenter.procduceMessage(data);
    }


    public void proucerMessage(PostData postData) {
//        LOGGER.info("发送需要post的信息到kafka:{}", postData);
        kafkaClient.produceData(postData);
    }
}
